/*!
 * 系统日志类
 *
 * 版权所有 2017 陈学芹 联系方式: 7219530@qq.com
 *
 * 本软件在GNU LGPL-V2.1协议下发布，欢迎使用.
 */

'use strict';
const axios = require('axios');
const EventEmitter = require('events');

function Beian(hostname) {
  this.hostname = hostname;
  this.myEmitter = new EventEmitter();
}

// Encapsulation in JavaScript 封装，继承，多态CRUD就属于多态一种
// The one disadvantage of overwriting the prototype is that
// the constructor property no longer points to the prototype,
// so we have to set it manually.
Beian.prototype = {
  constructor: Beian,

  startScan: function () {
    axios.get(`http://www.sojson.com/api/beian/${this.hostname}`).then( (response) => {
      this.myEmitter.emit('complete', response.data);
    });
  },

  on: function (event, callback) {
    this.myEmitter.on(event, callback);
  }

};

exports = module.exports = Beian;
